0

When i run my php file with the following code:

<?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

I have ran the php file below to check my extension list to see if '[xx] => mysql' is displayed which it isn't. I have added 'extension=php_mysql.dll' to 'php.ini' and restarted apache & mysql but this still isn't working. I have also added 'C:\xampp\php\ext' into the 'path' environmental variable. 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>'; 

?>

2 Answers2

0

mysql_xxx functions are deprecated, use mysqli_xxx or PDO instead.

http://php.net/manual/en/function.mysqli-connect.php

http://php.net/manual/en/book.pdo.php

Asfo
  • 413
  • 10
  • 20
0

Currently the use of mysql_connect function is not advisable because it is deprecated. Use mysqli or pdo instead. For example:

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

or

Look here for PDO

Community
  • 1
  • 1
rahimli
  • 1,373
  • 11
  • 25
  • 1
    'Currently' is the wrong word. The use of the `mysql_*` functions was discouraged as of PHP 5.5 and a deprecated warning was issued. As of PHP 7 these functions are **removed**. – Charlotte Dunois Mar 18 '16 at 22:25
  • is there any chance anyone could help me convert my code from mysql to mysqli, i'm unsure what i am doing? – SineadSmith90 Mar 18 '16 at 23:03