简体   繁体   English

PHP MySQL Xampp致命错误

[英]PHP mySQL xampp fatal error

When i run my php file with the following code: 当我使用以下代码运行php文件时:

<?php


//configurution of server 
$serve = mysql_connect('localhost', 'root', 'password');
if (!$serve) { echo 'error' ; }
$db = mysql_select_db('record', $serve);



//action to include 
if($_GET['action'] == 'include') {

    $name = $_GET ['name'];
    $lastname = $_GET['lastname'];

    $SQL = "insert into user (name, lastname) VALUES ('$name', '$lastname')";
    $re = mysql_query($SQL, $serve);
}



//action list 
if($_GET['action'] == 'userlist') {
    $SQL = "SELECT * FROM user";
    $re = mysql_query($SQL, $serve);
    $num = mysql_num_rows($re);

    if($num > 0) {

        //view screen
        while ($Line = mysql_fetch_object($re)) {
            echo "<b>Name: </b> {$Line->name} <b><br></b> 
                  <b>Lastname: </b> {$Line->lastname} </br><hr>";
        }
    }
    else {
        echo 'no user recorded';

    }
}
?>

This error appears: Fatal error: Call to undefined function mysql_connect() in C:\\xampp\\htdocs\\xampp\\record\\www\\connect.php on line 5 出现此错误:致命错误:在第5行的C:\\ xampp \\ htdocs \\ xampp \\ record \\ www \\ connect.php中调用未定义的函数mysql_connect()

I have ran the php file below to check my extension list to see if '[xx] => mysql' is displayed which it isn't. 我已经运行下面的php文件来检查我的扩展名列表,看是否显示了[[xx] => mysql”,但没有显示。 I have added 'extension=php_mysql.dll' to 'php.ini' and restarted apache & mysql but this still isn't working. 我已经将'extension = php_mysql.dll'添加到'php.ini'并重新启动了apache&mysql,但这仍然无法正常工作。 I have also added 'C:\\xampp\\php\\ext' into the 'path' environmental variable. 我还已经将'C:\\ xampp \\ php \\ ext'添加到'path'环境变量中。 I have checked the internet but can't seem to find a solution to my problem, can anyone please help me. 我已经检查了互联网,但似乎找不到解决我问题的方法,任何人都可以帮助我。 Thank-you. 谢谢。

<?php // extensions_list.php 

$list = get_loaded_extensions(); 
$list2 = array_map('strtolower',$list); 
sort($list2); 
echo '<pre>'.print_r($list2,true).'</pre>'; 

?>

Currently the use of mysql_connect function is not advisable because it is deprecated. 目前不建议使用mysql_connect函数,因为它已被弃用。 Use mysqli or pdo instead. 改用mysqli或pdo。 For example: 例如:

$connection = new mysqli($dbhost,$username,$password,$dbname); $query = "SAMPLE QUERY"; $connection->query($query);

or 要么

Look here for PDO 在这里寻找PDO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM