Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.