SQL Query

This section is for posting questions which are not directly related to WYSIWYG Web Builder.
Examples of off topics: web server configuration, hosting, programming related questions, third party scripts.

Note that these questions will generally not be answered by the administrators of this forum.
Post Reply
User avatar
Exiis
 
 
Posts: 7
Joined: Tue Jan 14, 2014 12:50 pm
Location: Meridian, ID
Contact:

SQL Query

Post by Exiis »

Need some help from someone who knows .PHP
The code I have below works on an older version of .php however our web hosting company is planning to upgrade to the latest version of .php. This code does not work on the latest release. Can someone help me fix it? Thanks!

<Database Connection Call Appears Here>

$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Oops some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Oops some thing went wrong");// we are now connected to database

$result = mysql_query("SELECT * FROM `OklahomaNRA` WHERE `id` ORDER BY RAND() LIMIT 15"); // selecting data through mysql_query()

echo '<table border=0px>'; // opening table tag
echo'<th>Subject</th><th>Url</th>'; //table headers

while($data = mysql_fetch_array($result))
{
// we are running a while loop to print all the rows in a table

echo '<table style="font-size:12px; font-family:Arial; color:black;">';

echo'<tr>'; // printing table row
echo '<td>'.$data['Subject'].'</td><td><a href="'.$data['Url'].'">'.$data['Url'].'</a></td></td> '; // we are looping all data to be printed till last row in the table
echo'</tr>'; // closing table row
}
?>
lummis
 
 
Posts: 211
Joined: Sun Apr 24, 2011 9:18 am
Location: UK

Re: SQL Query

Post by lummis »

I'm no expert in php but have experienced a similar problem. The answer was to update the MySQL functions to MySQLi, so change mysql_connect to mysqli_connect and mysql_query to mysqli_query.

If that doesn't work then maybe someone else can step in.

Brian
WWBman
 
 
Posts: 916
Joined: Fri Jan 08, 2010 6:10 pm

Re: SQL Query

Post by WWBman »

It’s not as simple as just adding the i to mysql.
Perhaps the following post might help.
http://www.wysiwygwebbuilder.com/forum/ ... li#p419295
User avatar
Exiis
 
 
Posts: 7
Joined: Tue Jan 14, 2014 12:50 pm
Location: Meridian, ID
Contact:

Re: SQL Query

Post by Exiis »

Thanks for the reply's; still not working. The guy from GoDaddy told me I was using retired/depreciated calls. Does that help?
WWBman
 
 
Posts: 916
Joined: Fri Jan 08, 2010 6:10 pm

Re: SQL Query

Post by WWBman »

So are you now using mysqli instead of mysql where appropriate in the correct format?
In what way is it still not working?
HankRock
 
 
Posts: 6
Joined: Tue Jan 22, 2019 9:05 pm

Re: SQL Query

Post by HankRock »

mysql_connect()
mysql_fetch_array()
mysql_query()
mysql_select_db()
These extensions were deprecated in PHP 5.5.0, and removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.
User avatar
Exiis
 
 
Posts: 7
Joined: Tue Jan 14, 2014 12:50 pm
Location: Meridian, ID
Contact:

Re: SQL Query

Post by Exiis »

Hi HankRock:

Thank you for the reply. I'm not a DB guy, this is the only call we make from the website. If I'm reading this correctly, I just need to change the "MySql" calls to "MySqli"?

The correct coding would be:

<Database Connection Call Appears Here>

$bd = mysqli_connect($mysqli_hostname, $mysqil_user, $mysqli_password) or die("Oops some thing went wrong");
mysqli_select_db($mysqli_database, $bd) or die("Oops some thing went wrong");// we are now connected to database

$result = mysqli_query("SELECT * FROM `OklahomaNRA` WHERE `id` ORDER BY RAND() LIMIT 15"); // selecting data through mysql_query()

echo '<table border=0px>'; // opening table tag
echo'<th>Subject</th><th>Url</th>'; //table headers

while($data = mysqi_fetch_array($result))
{
// we are running a while loop to print all the rows in a table

echo '<table style="font-size:12px; font-family:Arial; color:black;">';

echo'<tr>'; // printing table row
echo '<td>'.$data['Subject'].'</td><td><a href="'.$data['Url'].'">'.$data['Url'].'</a></td></td> '; // we are looping all data to be printed till last row in the table
echo'</tr>'; // closing table row
}
?>
WWBman
 
 
Posts: 916
Joined: Fri Jan 08, 2010 6:10 pm

Re: SQL Query

Post by WWBman »

Did you see my previous posts?
The calls are still in the wrong format.
E.g. should be: $result = mysqli_query($db, "......");
and mysqli_select_db($db, $mysql_database)
Post Reply