Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
491 views
in Technique[技术] by (71.8m points)

mysql - The following code returns an 500 error as the code is deprecited in php version 7, How to make it work in php verison 7?

Here is the code that used but return the 500 error in php version 7 and I totally screwed what to do with and could not find any documentation to do so.

<?php
// Create a new MySQL database connection
if (!$con = mysql_connect('localhost', 'root', 'password')) {
die('An error occurred while connecting to the MySQL server!<br><br>' . mysql_error());
}

if (!mysql_select_db(sample)) {
die('An error occurred while connecting to the database!<br><br>' . mysql_error());
}

// Create an array of MySQL queries to run
$sql = array(
'DROP TABLE IF EXISTS content;',
'CREATE TABLE content SELECT * FROM sample1.content'
);

// Run the MySQL queries
if (sizeof($sql) > 0) {
foreach ($sql as $query) {
if (!mysql_query($query)) {
die('A MySQL error has occurred!<br><br>' . mysql_error());
}
}
}

mysql_close($con);

?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are using an deprecated implementation of mysql that have been removed in php7.

Warning This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include: mysqli_query() PDO::query()

please check http://php.net/manual/en/function.mysql-query.php


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...