Page 1 of 1

SQL Query

Posted: Thu Feb 28, 2019 10:48 pm
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
}
?>

Re: SQL Query

Posted: Thu Feb 28, 2019 11:56 pm
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

Re: SQL Query

Posted: Thu Feb 28, 2019 11:59 pm
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

Re: SQL Query

Posted: Fri Mar 01, 2019 7:50 am
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?

Re: SQL Query

Posted: Fri Mar 01, 2019 9:10 am
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?

Re: SQL Query

Posted: Mon Mar 04, 2019 3:34 pm
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.

Re: SQL Query

Posted: Thu Mar 14, 2019 12:50 am
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
}
?>

Re: SQL Query

Posted: Thu Mar 14, 2019 9:16 am
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)