Fedora Core5(Bordeaux)のDVDでFC5をインストールして、yumでpostfix,php,php-gd,php-mbsting,php-mysql,mysql-serverも追加でインストールしました。

この状態で、コマンドライン版のPHPを用いて、MySQLを扱う関数を使えるようにするには、どのように設定したらよいでしょうか? 現在の状況は実行すると、phpのヘルプが表示されてしまいます。
[資料]
HTMLでのphpinfo();https://hgu.ac/test.php
コマンドラインでのphpinfo();https://hgu.ac/test.txt

回答の条件
  • 1人3回まで
  • 登録:
  • 終了:2006/09/29 07:05:02
※ 有料アンケート・ポイント付き質問機能は2023年2月28日に終了しました。

回答3件)

id:sera_yr No.1

回答回数123ベストアンサー獲得回数6

ポイント27pt

phpinfoの情報を見る限り、コマンドラインからのPHPでも既にMySQLを扱う関数は使えるようになっていると思います。

http://www.spencernetwork.org/memo/tips-6.php

こちらにてコマンドライン版のPHPの書式を再度確認し、ここにあるtest.phpを実行してみてはどうでしょうか。

test.phpが正しく実行されるようであれば、MySQLを扱う関数を記述しても正しく動作すると思います。

id:sarumack

回答ありがとうございます。

実は私も教えていただいたURLで確認して、CLI版のPHP単独では動作することを確認しました。

ところが、例えばそのスクリプトの後ろに、

  mysql_connect('localhost','user','pass');

を入れた途端、たぶんエラーなのかphpのヘルプメッセージが表示されてしまいます。

php(cli)とmysqlとの兼ね合いでどこが問題なのかご教示願えたら幸いです。

2006/09/23 06:56:48
id:elf No.2

回答回数76ベストアンサー獲得回数8

ポイント27pt

多分問題の原因を勘違いされていると思います.

その「たぶんエラーなのかphpのヘルプメッセージ」というのをGoogleなどにコピペするか回答にコピペしてみると解決の糸口がつかめると思います.

id:sarumack

6.emlはメール1通分です。

tips7.phpの中身は、

-----

#!/usr/bin/php -q

while(!feof(STDIN)){

$line=fgets(STDIN);

//件名取得

if(substr($line,0,8) == "Subject:"){

$subject=trim(substr($line,8));

}

//アドレス取得

if(substr($line,0,5) == "From:"){

$addr=trim(substr($line,5));

}

}

echo "subject=$subject\n";

echo "address=$addr\n";

mysql_connect('localhost','user','pass');

//mysql_select_db('mms_db');

//mysql_query('set character set utf8'); //「はてな」を参照

//$sql="update t_student set s_kaddr='$addr' where s_id='$subject';

//mysql_query($sql);

?>

-----

です。これで次を実行するとこんなになります。

[root@xoops mms]# cat 6.eml | ./tips7.php

Usage: php [options] [-f] <file> [--] [args...]

php [options] -r [--] [args...]

php [options] [-B <begin_code>] -R [-E <end_code>] [--] [args...]

php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]

php [options] -- [args...]

php [options] -a

-a Run interactively

-c <path>|<file> Look for php.ini file in this directory

-n No php.ini file will be used

-d foo[=bar] Define INI entry foo with value 'bar'

-e Generate extended information for debugger/profiler

-f <file> Parse <file>.

-h This help

-i PHP information

-l Syntax check only (lint)

-m Show compiled in modules

-r Run PHP without using script tags

-B <begin_code> Run PHP <begin_code> before processing input lines

-R Run PHP for every input line

-F <file> Parse and execute <file> for every input line

-E <end_code> Run PHP <end_code> after processing all input lines

-H Hide any passed arguments from external tools.

-s Display colour syntax highlighted source.

-v Version number

-w Display source with stripped comments and whitespace.

-z <file> Load Zend extension <file>.

args... Arguments passed to script. Use -- args when first argument

starts with - or script is read from stdin

--rf <name> Show information about function <name>.

--rc <name> Show information about class <name>.

--re <name> Show information about extension <name>.

2006/09/25 03:33:46
id:sera_yr No.3

回答回数123ベストアンサー獲得回数6

ポイント26pt

tips7.phpの2行目に「<?php」が無いようですが、コピペミスでしょうか。もしソースに無いのであれば原因はこれではないかと思います。

ソースに「<?php」があってなお、同じような現象がおきているのであれば、以下のソースで試してみてはいかがでしょうか。

#!/usr/bin/php -q

<?php

$ret = mysql_connect('localhost','user','pass');

if( $ret === false ) echo "error";

?>

id:sarumack

回答ありがとうございました。

「<?php」はコピーミスです。申し訳ありません。

教えていただいたソースをtips8.phpとして実行してみました。結果は以下のとおりでした。

----

[yamamoto@xoops mms]$ ./tips8.php

Usage: php [options] [-f] <file> [--] [args...]

php [options] -r [--] [args...]

php [options] [-B <begin_code>] -R [-E <end_code>] [--] [args...]

php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]

php [options] -- [args...]

php [options] -a

-a Run interactively

-c <path>|<file> Look for php.ini file in this directory

-n No php.ini file will be used

-d foo[=bar] Define INI entry foo with value 'bar'

-e Generate extended information for debugger/profiler

-f <file> Parse <file>.

-h This help

-i PHP information

-l Syntax check only (lint)

-m Show compiled in modules

-r Run PHP without using script tags

-B <begin_code> Run PHP <begin_code> before processing input lines

-R Run PHP for every input line

-F <file> Parse and execute <file> for every input line

-E <end_code> Run PHP <end_code> after processing all input lines

-H Hide any passed arguments from external tools.

-s Display colour syntax highlighted source.

-v Version number

-w Display source with stripped comments and whitespace.

-z <file> Load Zend extension <file>.

args... Arguments passed to script. Use -- args when first argument

starts with - or script is read from stdin

--rf <name> Show information about function <name>.

--rc <name> Show information about class <name>.

--re <name> Show information about extension <name>.

2006/09/25 22:27:08

コメントはまだありません

この質問への反応(ブックマークコメント)

トラックバック

「あの人に答えてほしい」「この質問はあの人が答えられそう」というときに、回答リクエストを送ってみてましょう。

これ以上回答リクエストを送信することはできません。制限について

回答リクエストを送信したユーザーはいません