php数据库查询代码 php数据库查询系统

PHP查询代码怎么写?连接数据库
代码如下
?php
$conn = @mysql_connect("localhost","root","root") or die ("database error");
mysql_select_db("DB",$conn);
if (isset($_POST['submit'])){
$num=$_POST['num'];
$sql="SELECT num FROM TEST WHERE num=$num";
$tt=mysql_query($sql,$conn);
$row = mysql_fetch_assoc($tt);
echo "num:".$row['num']."/br";
}
?
几种常用PHP连接数据库的代码示例PHP连接数据库之PHP连接MYSQL数据库代码
?php$mysql_server_name= localhost ;//改成自己的mysql数据库服务器$mysql_username= root ;//改成自己的mysql数据库用户名$mysql_password= ;//改成自己的mysql数据库密码$mysql_database= mycounter ;//改成自己的mysql数据库名$conn=mysql_connect($mysql_server_name $mysql_username $mysql_password $mysql_database);$sql= CREATE DATABASE mycounterDEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;;mysql_query($sql);$sql= CREATE TABLE `counter`(`id` INT( ) UNSIGNED NOT NULLAUTO_INCREMENT`count` INT( )UNSIGNED NOT NULL DEFAULTPRIMARY KEY( `id` ) ) TYPE = innodb; ;mysql_select_db($mysql_database $conn);$result=mysql_query($sql);//echo $sql;mysql_close($conn);echo "Hello!数据库mycounter已经成功建立!";?
PHP连接数据库之PHP连接ACCESS数据库代码方法
?$conn = new ("ADODB Connection");$connstr = "DRIVER={Microsoft Access Driver (* mdb)}; DBQ="realpath("data/db mdb");$conn Open($connstr);$rs = new ("ADODB RecordSet");$rs Open("select * from szd_t" $conn );while(! $rs eof) {$f = $rs Fields( );echo $f value;$rs MoveNext();}?
PHP连接数据库之PHP连接MS SQL数据库代码方法
安装SQL服务器并添加PHP的MSSQL扩展
使用以下代码连接并测试
?php$myServer = localhost; //主机$myUser = sa; //用户名$myPass = password; //密码$myDB = Northwind; //MSSQL库名$s = @mssql_connect($myServer$myUser$myPass)or die(Couldnt connect to SQL Server on $myServer);$d = @mssql_select_db($myDB$s)or die(Couldnt open database $myDB);$query = SELECT TitleOfCourtesy+ +FirstName+ +LastName AS Employee ;$query= FROM Employees ;$query= WHERECountry=USA AND Left(HomePhone) = ( );$result = mssql_query($query);$numRows = mssql_num_rows($result);echoh$numRowsRow($numRows ==? : s)Returned / h ;while($row = mssql_fetch_array($result)){echoli$row[Employee]/li;}?
PHP连接数据库之PHP连接Oracle数据库
PHP提供了两套函数与Oracle连接 分别是ORA_和OCI函数 其中ORA_函数略显陈旧 OCI函数更新据说更好一些 两者的使用语法几乎相差无几 你的PHP安装选项应该可以支持两者的使用
?if ($conn=Ora_Logon("user@TNSNAME" "password")){ echo "SUCCESS ! Connected to databasen";}else{echo "Failed : ( Could not connect to databasen";}Ora_Logoff($conn);phpinfo();?lishixinzhi/Article/program/PHP/201405/30761
PHP中写一个数据库查询的类的方法代码要如何写?php
if(!defined("INCLUDE_MYSQL_OK")) {
define("INCLUDE_MYSQL_OK","");
class MySQL_class {
var $debug = true;
var $db,
$id,
$result,/* 查询结果指针 */
$rows,/* 查询结果行数 */
$fields,/* 查询结果列数 */
$data,/* 数据结果 */
$arows,/* 发生作用的纪录行数目 */
$iid;/* 上次插入操作后 , 可能存在的"AUTO_INCREMENT"属性字段的值 , 如果为"0" , 则为空 */
var $user, $pass, $host, $charset;
/*
* 请注意用户名和密码是否正确
*/
function Setup ($host, $user, $pass, $charset='utf8') {
$this-host = $host;
$this-user = $user;
$this-pass = $pass;
$this-charset = $charset;
}
function Connect ($db = "") {
global $CFG_MYSQL_INFO;
if (!$this-host) {
$this-host = $CFG_MYSQL_INFO["host"];
}
if (!$this-user) {
$this-user = $CFG_MYSQL_INFO["user"];/* 在这里作修改 */
}
if (!$this-pass) {
$this-pass = $CFG_MYSQL_INFO["passwd"]; /* 在这里作修改 */

推荐阅读