PHP ~ MySQL DB Class
define('HOSTNAME', 'localhost');
define('USERNAME', 'root');
define('PASSWORD', '12321313213123');
define('DATABASE', 'gold');
class DB
{
private $dbLink;
private $result;
public function __construct()
{
$this->connect();
}
protected function connect()
{
$this->dbLink = mysqli_connect(HOSTNAME,USERNAME,PASSWORD,DATABASE);
}
public function query($sql)
{
$this->result = mysqli_query($this->dbLink, $sql);
}
public function fetch()
{
return mysqli_fetch_array($this->result);
}
public function close()
{
mysqli_close($this->dbLink);
}
}
$db = new DB();
$sql = "SELECT * FROM prices";
$db->query($sql);
while($x = $db->fetch())
{
print $x['buy'].',';
}
$db->close();
PHP ~ MsSQL DB Class
define('HOSTNAME', 'BITTY-NOTEBOOK\SQLEXPRESS');
define('USERNAME', 'sa');
define('PASSWORD', '4785735');
define('DATABASE', 'Gold');
class DB{
private $dbLink;
private $result;
public function __construct()
{
$this->connect();
}
protected function connect()
{
$this->dbLink = mssql_connect(HOSTNAME, USERNAME, PASSWORD) or die("Couldn't connect to SQL Server");
if (!$this->dbLink || !mssql_select_db(DATABASE, $this->dbLink))
{
die('Unable to connect or select database!');
}
}
public function query($sql)
{
$this->result = mssql_query($sql, $this->dbLink);
}
public function fetch()
{
return mssql_fetch_array($this->result);
}
public function close()
{
mssql_close($this->dbLink);
}
}
$db = new DB();
$sql = "INSERT INTO [Gold].[dbo].[Prices] ([Buy] ,[Sell] ,[Time]) VALUES (".$buy." ,".$sell." ,'".$time."')";
$db->query($sql);
$db->close();
PHP ~ connect to Microsoft SQL Server ~ MsSQL
Download the file ntwdblib.dll
file version: 2000.80.194.0
put it into the php folder and apache folder and Windows\System32\
for example of mine~~~put it into
D:\wamp\bin\php\php5.2.5\ntwdblib.dll
D:\wamp\bin\apache\apache2.2.8\bin\ntwdblib.dll
C:\Windows\System32\\ntwdblib.dll
restart sql server~apache~php
then it works~
PHP Code
======================================================================
$myServer = "BITTY-NOTEBOOK\SQLEXPRESS";
$myUser = "sa";
$myPass = "1234567890";
$myDB = "Gold";
$link = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer");
if (!$link || !mssql_select_db($myDB, $link)) {
die('Unable to connect or select database!');
}
$sql = "SELECT [ID],[Buy],[Sell],[Time] FROM [Gold].[dbo].[Prices]";
$r = mssql_query($sql, $link);
while($x = mssql_fetch_array($r))
{
print $x['Buy'];
}
mssql_close($link);
======================================================================
http://www.9enjoy.com/post/236/
file version: 2000.80.194.0
put it into the php folder and apache folder and Windows\System32\
for example of mine~~~put it into
D:\wamp\bin\php\php5.2.5\ntwdblib.dll
D:\wamp\bin\apache\apache2.2.8\bin\ntwdblib.dll
C:\Windows\System32\\ntwdblib.dll
restart sql server~apache~php
then it works~
PHP Code
======================================================================
$myServer = "BITTY-NOTEBOOK\SQLEXPRESS";
$myUser = "sa";
$myPass = "1234567890";
$myDB = "Gold";
$link = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer");
if (!$link || !mssql_select_db($myDB, $link)) {
die('Unable to connect or select database!');
}
$sql = "SELECT [ID],[Buy],[Sell],[Time] FROM [Gold].[dbo].[Prices]";
$r = mssql_query($sql, $link);
while($x = mssql_fetch_array($r))
{
print $x['Buy'];
}
mssql_close($link);
======================================================================
http://www.9enjoy.com/post/236/
MSSQL ~ Login failed for user 'sa'. (Microsoft SQL Server, Error: 18470)
login by Windows Authentication
follow the steps

http://blog.csdn.net/Joetao/archive/2009/06/08/4252327.aspx
follow the steps
http://blog.csdn.net/Joetao/archive/2009/06/08/4252327.aspx
訂閱:
文章 (Atom)