Am getting this error when connecting to mysql using PHP script. Need help.
[15-Jun-2017 04:58:55 CST6CDT] PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /xxx/xxx/public_html/app/sikacon.php:8
Stack trace:
#0 {main}
thrown in /xxx/xxx/public_html/app/sikacon.php on line 8
This is the scripts.
<?php
$host = "xxxxx";
$user = "xxxxx";
$pw = "xxxx";
$db = "xxxxx";
$con = mysql_connect($host,$user,$pw) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES 'utf8'");
$action = $_GET["action"];
switch ($action)
{
case "CountPersons":
$q = mysql_query("SELECT * FROM DepositTransactions");
$count = mysql_num_rows($q);
print json_encode($count);
break;
Case "GetPersons":
$q = mysql_query("SELECT AccountNumber, MemberID FROM DepositTransactions");
$rows = array();
while($r = mysql_fetch_assoc($q))
{
$rows[] = $r;
}
print json_encode($rows);
break;
case "InsertNewPerson":
$name = $_GET["name"];
$age = $_GET["age"];
$q = mysql_query("INSERT INTO UserRegister (CustomerName, CustomerNo) VALUES ('$name', $age)");
print json_encode("Inserted");
break;
}
?>
[15-Jun-2017 04:58:55 CST6CDT] PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /xxx/xxx/public_html/app/sikacon.php:8
Stack trace:
#0 {main}
thrown in /xxx/xxx/public_html/app/sikacon.php on line 8
This is the scripts.
<?php
$host = "xxxxx";
$user = "xxxxx";
$pw = "xxxx";
$db = "xxxxx";
$con = mysql_connect($host,$user,$pw) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES 'utf8'");
$action = $_GET["action"];
switch ($action)
{
case "CountPersons":
$q = mysql_query("SELECT * FROM DepositTransactions");
$count = mysql_num_rows($q);
print json_encode($count);
break;
Case "GetPersons":
$q = mysql_query("SELECT AccountNumber, MemberID FROM DepositTransactions");
$rows = array();
while($r = mysql_fetch_assoc($q))
{
$rows[] = $r;
}
print json_encode($rows);
break;
case "InsertNewPerson":
$name = $_GET["name"];
$age = $_GET["age"];
$q = mysql_query("INSERT INTO UserRegister (CustomerName, CustomerNo) VALUES ('$name', $age)");
print json_encode("Inserted");
break;
}
?>