Saturday, April 28, 2018

php - PHP7 compatibility



Im looking for fix for PHP7 compatibility.
I have code which working well with PHP 5.6.2.



Can you please help me to work with PHP7?



$select = "SELECT post_title , ID FROM  wp_posts ORDER BY ID DESC LIMIT 60";

$sql1= mysql_query($select);
$a = 1;
while($row = mysql_fetch_array($sql1)){ ?>
div class="form-group">



}
?>



Thank you.
Best Regards
Jiri


Answer



Even when running PHP 5.6.2 you should have seen the deprecation notices for the mysql_* functions, and they have been completely removed in PHP 7. Fortunately, you can use the mysqli_* functions without really changing your code much.



The primary difference in this example (aside from adding an i to your function names) is that now you'll need to explicitly use the link identifier returned by mysqli_connect() or mysqli_init() which is different because previously if the link identifier was not specified, then the last link opened by mysql_connect() was assumed. This is now required.





// get a link to the connection
$link = mysqli_connect("localhost", "my_user", "my_password", "my_db");

$select = "SELECT post_title , ID FROM wp_posts ORDER BY ID DESC LIMIT 60";

// use the link here
// change mysql_query -> mysqli_query
$sql1= mysqli_query($link, $select);


$a = 1;

// change mysql_fetch_array -> mysqli_fetch_array
while($row = mysqli_fetch_array($sql1)){ ?>
div class="form-group">




}
?>

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...