Jump to content

PHP CLI


fikri215

Recommended Posts

I'm using PHP version 5.1.6 and mysql. In my case i tried to run php in commnad line interface, i have no problem to 'echo' simple statement such as "Hello My World".

 

i put this line in my hello.php

#!/usr/bin/php

<?php

echo "Hello My World\n";

?>

and then run this command:

[root@anas]# php hello.php

Hello My World

[root@anas]#

 

But, when i tried to connect to mysql, i added these lines:

#!/usr/bin/php

<?php

echo "Hello My World\n";

$conn=mysql_connect('localhost','root','password');

if(!@$conn)

{

echo "Connection Refused!";

}

else

echo "Connection Accepted";

 

mysql_close($conn);

?>

 

i ran the  command:

[root@anas]# php hello.php

Hello My World

PHP Fatal error:  Call to undefined function mysql_connect() in /home/anaz/phpcli/truncate.php on line 4

[root@anas]#

 

I try to add run this file in the browser using apache webserver. The peocess was success. I got that error only in PHP CLI.

 

Can anyone help me to identify the problem and make the solution.

Link to comment
https://forums.phpfreaks.com/topic/55699-php-cli/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.