来自PHP测试文件的SQL连接字符串 [英] Sql connection string from php test file
本文介绍了来自PHP测试文件的SQL连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要根据用于测试数据库的PHP测试代码设置SQL连接字符串
这是我制作的字符串(不起作用)
数据源= something.com:3631;初始目录=数据库;用户ID = Neo;密码= qwerty;"
这是测试php文件,我做错什么了吗?
请注意php文件确实可以工作
I need to set a SQL connection string based on a PHP test code used to test the database
here is the string i have made(does not work)
"Data Source=something.com:3631;Initial Catalog=database;User Id=Neo;Password=qwerty;"
here is the test php file, Did i make something wrong?
note the php file does work
<?php
$dbname = 'database';
$server = 'something.com:3631';
$username = 'Neo';
$password = 'qwerty';
$sqlquery = "SELECT * FROM sometable ;";
//$sqlquery = "INSERT INTO sometable (fSite, Area, fColumn, Shelf, Item, Quantity) VALUES ('600','FA','8012','3','577300','200');";
$data = mssqlExec($sqlquery, $dbname, $server, $username, $password, $type=MSSQL_ASSOC);
print_r($data);
/**
* Generic Sybase connection to MS SQL using Linux box.
*
* @param int $type Can be MSSQL_ASSOC, MSSQL_NUM or MSSQL_BOTH These are constants (numbers) so do not put quotes around them.
* @param string $sqlquery the sql query, ensure no semicolon on the end and double quotes with backslashes for name with spaces
* @param string $dbname name of the database
* @param string $server name of the server it is hosted on
* @param string $username username associated with the database
* @param string $password passsword for that user
* @param global $db_error contains relevant error message for debugging
*
* @returns array $results Returns a mutildimensional array with rows an array of fields and values
* (row0=>(field0=>value0,field1=>value1),row1=>(field0=>value0,filed1=>value1))
*
* EXAMPLE: mssqlExec("SELECT Field FROM Table", "PROD1", "sql2.network.com", "fred", "pass", MSSQL_BOTH);
*/
function mssqlExec($sqlquery, $dbname, $server, $username, $password, $type=MSSQL_ASSOC)
{
global $db_error;
$sqlconnect=mssql_connect($server,$username,$password);
if (!$sqlconnect) {
$db_error = "Could not Connect to $server";
return FALSE;
}
$sqldb=mssql_select_db($dbname,$sqlconnect);
$process=mssql_query($sqlquery);
if(!$process) {
$db_error = "Query did not return any results";
return FALSE;
}
$chk = substr($sqlquery, 0, 6);
if ($chk == 'SELECT') {
while ($row=mssql_fetch_array($process,$type)) {
foreach ($row as $colNum=>$value) {
$trimmed[$colNum] = trim($value);
}
$results[]=$trimmed;
}
} else {
$results = TRUE;
}
mssql_close($sqlconnect);
return $results;
}
?>
我正在使用MS Visual Studio 2010和ssql服务器2008
I am using MS Visual studio 2010 and ssql server 2008
推荐答案
dbname = ' 数据库';
dbname = 'database';
服务器 = '
server = 'something.com:3631';
用户名 = '
username = 'Neo';
这篇关于来自PHP测试文件的SQL连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文