mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 08:58:56 +00:00
examples: synchronized and adapted to PEAR Coding Standards
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@291759 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
5ab48bfb18
commit
55196866bf
22 changed files with 139 additions and 173 deletions
|
@ -121,7 +121,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Connect to MSSQL
|
||||
// Connect to MSSQL and select the database
|
||||
mssql_connect('KALLESPC\SQLEXPRESS', 'sa', 'phpfi');
|
||||
mssql_select_db('php');
|
||||
|
||||
|
@ -129,9 +129,9 @@ mssql_select_db('php');
|
|||
$stmt = mssql_init('NewUserRecord');
|
||||
|
||||
// Bind the field names
|
||||
mssql_bind($stmt, '@username', 'Kalle', SQLVARCHAR, false, false, 60);
|
||||
mssql_bind($stmt, '@name', 'Kalle', SQLVARCHAR, false, false, 60);
|
||||
mssql_bind($stmt, '@age', 19, SQLINT1, false, false, 3);
|
||||
mssql_bind($stmt, '@username', 'Kalle', SQLVARCHAR, false, false, 60);
|
||||
mssql_bind($stmt, '@name', 'Kalle', SQLVARCHAR, false, false, 60);
|
||||
mssql_bind($stmt, '@age', 19, SQLINT1, false, false, 3);
|
||||
|
||||
// Execute
|
||||
mssql_execute($stmt);
|
||||
|
|
|
@ -115,11 +115,11 @@
|
|||
// <server>,<port> when using a non default port number
|
||||
$server = 'KALLESPC\SQLEXPRESS';
|
||||
|
||||
// Connect to MSSQL
|
||||
$link = mssql_connect($server, 'sa', 'phpfi');
|
||||
|
||||
if(!$link)
|
||||
{
|
||||
die('Something went wrong while connecting to MSSQL');
|
||||
if (!$link) {
|
||||
die('Something went wrong while connecting to MSSQL');
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -61,27 +61,24 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Connect to MSSQL
|
||||
// Connect to MSSQL and select the database
|
||||
$link = mssql_connect('MANGO\SQLEXPRESS', 'sa', 'phpfi');
|
||||
mssql_select_db('php', $link);
|
||||
|
||||
// Select all people
|
||||
$result = mssql_query('SELECT [name], [age] FROM [persons] WHERE [age] >= 13');
|
||||
|
||||
if(!$result)
|
||||
{
|
||||
if (!$result) {
|
||||
die('Query failed.');
|
||||
}
|
||||
|
||||
// Select every 4th student in the results
|
||||
for($i = mssql_num_rows($result) - 1; $i % 4; $i++)
|
||||
{
|
||||
if(!mssql_data_seek($result, $i))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for ($i = mssql_num_rows($result) - 1; $i % 4; $i++) {
|
||||
if (!mssql_data_seek($result, $i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fetch the row ...
|
||||
// Fetch the row ...
|
||||
}
|
||||
|
||||
// Free the query result
|
||||
|
|
|
@ -58,9 +58,9 @@ $title = 'Test of blogging system';
|
|||
$content = 'If you can read this, then the new system is compatible with MSSQL';
|
||||
|
||||
// Bind values
|
||||
mssql_bind($stmt, '@author', 'Felipe Pena', SQLVARCHAR, false, false, 60);
|
||||
mssql_bind($stmt, '@date', '08/10/2008', SQLVARCHAR, false, false, 20);
|
||||
mssql_bind($stmt, '@title', $title, SQLVARCHAR, false, false, 60);
|
||||
mssql_bind($stmt, '@author', 'Felipe Pena', SQLVARCHAR, false, false, 60);
|
||||
mssql_bind($stmt, '@date', '08/10/2008', SQLVARCHAR, false, false, 20);
|
||||
mssql_bind($stmt, '@title', $title, SQLVARCHAR, false, false, 60);
|
||||
mssql_bind($stmt, '@content', $content, SQLTEXT);
|
||||
|
||||
// Execute the statement
|
||||
|
|
|
@ -75,20 +75,16 @@
|
|||
$query = mssql_query('SELECT [username], [name] FROM [php].[dbo].[userlist]');
|
||||
|
||||
// Check if there were any records
|
||||
if(!mssql_num_rows($query))
|
||||
{
|
||||
echo 'No records found';
|
||||
}
|
||||
else
|
||||
{
|
||||
// The following is equal to the code below:
|
||||
//
|
||||
// while($row = mssql_fetch_row($query))
|
||||
if (!mssql_num_rows($query)) {
|
||||
echo 'No records found';
|
||||
} else {
|
||||
// The following is equal to the code below:
|
||||
//
|
||||
// while ($row = mssql_fetch_row($query)) {
|
||||
|
||||
while($row = mssql_fetch_array($query, MSSQL_NUM))
|
||||
{
|
||||
// ...
|
||||
}
|
||||
while ($row = mssql_fetch_array($query, MSSQL_NUM)) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
||||
// Free the query result
|
||||
|
|
|
@ -57,23 +57,21 @@
|
|||
$query = mssql_query('SELECT [username], [name] FROM [php].[dbo].[userlist]');
|
||||
|
||||
// Check if there were any records
|
||||
if(!mssql_num_rows($query))
|
||||
{
|
||||
echo 'No records found';
|
||||
if (!mssql_num_rows($query)) {
|
||||
echo 'No records found';
|
||||
}
|
||||
else
|
||||
{
|
||||
// Print a nice list of users in the format of:
|
||||
// * name (username)
|
||||
// Print a nice list of users in the format of:
|
||||
// * name (username)
|
||||
|
||||
echo '<ul>';
|
||||
echo '<ul>';
|
||||
|
||||
while($row = mssql_fetch_assoc($query))
|
||||
{
|
||||
echo '<li>' . $row['name'] . ' (' . $row['username'] . ')</li>';
|
||||
}
|
||||
while ($row = mssql_fetch_assoc($query)) {
|
||||
echo '<li>' . $row['name'] . ' (' . $row['username'] . ')</li>';
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
// Free the query result
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Connect to MSSQL
|
||||
// Connect to MSSQL and select the database
|
||||
$link = mssql_connect('MANGO\SQLEXPRESS', 'sa', 'phpfi');
|
||||
mssql_select_db('php', $link);
|
||||
|
||||
|
@ -57,20 +57,17 @@ mssql_select_db('php', $link);
|
|||
$result = mssql_query('SELECT * FROM [php].[dbo].[people]', $link, 100);
|
||||
$records = 10;
|
||||
|
||||
while($records >= 0)
|
||||
{
|
||||
while($row = mssql_fetch_assoc($result))
|
||||
{
|
||||
// Do stuff ...
|
||||
}
|
||||
while ($records >= 0) {
|
||||
while ($row = mssql_fetch_assoc($result)) {
|
||||
// Do stuff ...
|
||||
}
|
||||
|
||||
--$records;
|
||||
--$records;
|
||||
}
|
||||
|
||||
if($batchsize = mssql_fetch_batch($result))
|
||||
{
|
||||
// $batchsize is the number of records left
|
||||
// in the result, but not shown above
|
||||
if ($batchsize = mssql_fetch_batch($result)) {
|
||||
// $batchsize is the number of records left
|
||||
// in the result, but not shown above
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Connect MSSQL
|
||||
// Connect to MSSQL and select the database
|
||||
mssql_connect('MANGO\SQLEXPRESS', 'sa', 'phpfi');
|
||||
mssql_select_db('php');
|
||||
|
||||
|
@ -116,17 +116,16 @@ echo '</thead>';
|
|||
// Dump all fields
|
||||
echo '<tbody>';
|
||||
|
||||
for($i = 0; $i < mssql_num_fields($query); ++$i)
|
||||
{
|
||||
// Fetch the field information
|
||||
$field = mssql_fetch_field($query, $i);
|
||||
for ($i = 0; $i < mssql_num_fields($query); ++$i) {
|
||||
// Fetch the field information
|
||||
$field = mssql_fetch_field($query, $i);
|
||||
|
||||
// Print the row
|
||||
echo '<tr>';
|
||||
echo '<td>' . $field->name . '</td>';
|
||||
echo '<td>' . strtoupper($field->type) . '</td>';
|
||||
echo '<td>' . $field->max_length . '</td>';
|
||||
echo '</tr>';
|
||||
// Print the row
|
||||
echo '<tr>';
|
||||
echo '<td>' . $field->name . '</td>';
|
||||
echo '<td>' . strtoupper($field->type) . '</td>';
|
||||
echo '<td>' . $field->max_length . '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
echo '</tbody>';
|
||||
|
|
|
@ -64,23 +64,19 @@
|
|||
$query = mssql_query('SELECT [username], [name] FROM [php].[dbo].[userlist]');
|
||||
|
||||
// Check if there were any records
|
||||
if(!mssql_num_rows($query))
|
||||
{
|
||||
echo 'No records found';
|
||||
}
|
||||
else
|
||||
{
|
||||
// Print a nice list of users in the format of:
|
||||
// * name (username)
|
||||
if (!mssql_num_rows($query)) {
|
||||
echo 'No records found';
|
||||
} else {
|
||||
// Print a nice list of users in the format of:
|
||||
// * name (username)
|
||||
|
||||
echo '<ul>';
|
||||
echo '<ul>';
|
||||
|
||||
while($row = mssql_fetch_object($query))
|
||||
{
|
||||
echo '<li>' . $row->name . ' (' . $row->username . ')</li>';
|
||||
}
|
||||
while ($row = mssql_fetch_object($query)) {
|
||||
echo '<li>' . $row->name . ' (' . $row->username . ')</li>';
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
// Free the query result
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Connect to server and database
|
||||
// Connect to MSSQL and select the database
|
||||
$link = mssql_connect('MANGO\SQLEXPRESS', 'sa', 'phpfi');
|
||||
mssql_select_db('php', $link);
|
||||
|
||||
|
@ -66,9 +66,8 @@ mssql_select_db('php', $link);
|
|||
$query = mssql_query('SELECT [id], [quote] FROM [quotes] WHERE [id] = \'42\'', $link);
|
||||
|
||||
// Did the query failed?
|
||||
if(!$query)
|
||||
{
|
||||
die('MSSQL error: ' . mssql_get_last_message());
|
||||
if (!$query) {
|
||||
die('MSSQL error: ' . mssql_get_last_message());
|
||||
}
|
||||
|
||||
// Fetch the row
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Connect MSSQL
|
||||
// Connect to MSSQL and select the database
|
||||
mssql_connect('MANGO\SQLEXPRESS', 'sa', 'phpfi');
|
||||
mssql_select_db('php');
|
||||
|
||||
|
|
|
@ -65,9 +65,8 @@ $query = mssql_query('SELECT [username], [name], [email] FROM [php].[dbo].[userl
|
|||
echo 'Result set contains the following field(s):', PHP_EOL;
|
||||
|
||||
// Dump all field names in result
|
||||
for($i = 0; $i < mssql_num_fields($query); ++$i)
|
||||
{
|
||||
echo ' - ' . mssql_field_name($query, $i), PHP_EOL;
|
||||
for ($i = 0; $i < mssql_num_fields($query); ++$i) {
|
||||
echo ' - ' . mssql_field_name($query, $i), PHP_EOL;
|
||||
}
|
||||
|
||||
// Free the query result
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Connect MSSQL
|
||||
// Connect to MSSQL and select the database
|
||||
mssql_connect('MANGO\SQLEXPRESS', 'sa', 'phpfi');
|
||||
mssql_select_db('php');
|
||||
|
||||
|
@ -83,23 +83,22 @@ echo '</thead>';
|
|||
// Dump all fields
|
||||
echo '<tbody>';
|
||||
|
||||
for($i = 0; $i < mssql_num_fields($query); ++$i)
|
||||
{
|
||||
// Fetch the field information, notice the
|
||||
// field_offset parameter is not set. See
|
||||
// the mssql_field_seek call below
|
||||
$field = mssql_fetch_field($query);
|
||||
for ($i = 0; $i < mssql_num_fields($query); ++$i) {
|
||||
// Fetch the field information, notice the
|
||||
// field_offset parameter is not set. See
|
||||
// the mssql_field_seek call below
|
||||
$field = mssql_fetch_field($query);
|
||||
|
||||
// Print the row
|
||||
echo '<tr>';
|
||||
echo '<td>' . $field->name . '</td>';
|
||||
echo '<td>' . strtoupper($field->type) . '</td>';
|
||||
echo '<td>' . $field->max_length . '</td>';
|
||||
echo '</tr>';
|
||||
// Print the row
|
||||
echo '<tr>';
|
||||
echo '<td>' . $field->name . '</td>';
|
||||
echo '<td>' . strtoupper($field->type) . '</td>';
|
||||
echo '<td>' . $field->max_length . '</td>';
|
||||
echo '</tr>';
|
||||
|
||||
// Move the internal seek pointer to the next
|
||||
// row in the result set
|
||||
mssql_field_seek($query, $i + 1);
|
||||
// Move the internal seek pointer to the next
|
||||
// row in the result set
|
||||
mssql_field_seek($query, $i + 1);
|
||||
}
|
||||
|
||||
echo '</tbody>';
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Connect MSSQL
|
||||
// Connect to MSSQL and select the database
|
||||
mssql_connect('MANGO\SQLEXPRESS', 'sa', 'phpfi');
|
||||
mssql_select_db('php');
|
||||
|
||||
|
@ -67,9 +67,9 @@ mssql_select_db('php');
|
|||
$query = mssql_query('SELECT [name] FROM [php].[dbo].[persons]');
|
||||
|
||||
// Print the field type and length
|
||||
echo '\'' . mssql_field_name($query, 0) . '\' is a type of ' .
|
||||
strtoupper(mssql_field_type($query, 0)) .
|
||||
'(' . mssql_field_length($query, 0) . ')';
|
||||
echo '\'' . mssql_field_name($query, 0) . '\' is a type of ' .
|
||||
strtoupper(mssql_field_type($query, 0)) .
|
||||
'(' . mssql_field_length($query, 0) . ')';
|
||||
|
||||
// Free the query result
|
||||
mssql_free_result($query);
|
||||
|
|
|
@ -38,18 +38,17 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Connect to MSSQL
|
||||
// Connect to MSSQL and select the database
|
||||
mssql_connect('KALLESPC\SQLEXPRESS', 'sa', 'phpfi');
|
||||
mssql_select_db('php');
|
||||
|
||||
// Make a query that will fail
|
||||
$query = @mssql_query('SELECT * FROM [php].[dbo].[not-found]');
|
||||
|
||||
if(!$query)
|
||||
{
|
||||
// The query has failed, print a nice error message
|
||||
// using mssql_get_last_message()
|
||||
die('MSSQL error: ' . mssql_get_last_message());
|
||||
if (!$query) {
|
||||
// The query has failed, print a nice error message
|
||||
// using mssql_get_last_message()
|
||||
die('MSSQL error: ' . mssql_get_last_message());
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Connect to MSSQL
|
||||
// Connect to MSSQL and select the database
|
||||
mssql_connect('KALLESPC\SQLEXPRESS', 'sa', 'phpfi');
|
||||
mssql_select_db('php');
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Connect to MSSQL
|
||||
// Connect to MSSQL and select the database
|
||||
mssql_connect('KALLESPC\SQLEXPRESS', 'sa', 'phpfi');
|
||||
mssql_select_db('php');
|
||||
|
||||
|
@ -62,9 +62,8 @@ mssql_min_error_severity(1);
|
|||
// square brackets around the field and table names.
|
||||
$query = mssql_query('SELECT `syntax`, `error` FROM `MSSQL`');
|
||||
|
||||
if(!$query)
|
||||
{
|
||||
// Custom error handler ...
|
||||
if (!$query) {
|
||||
// Custom error handler ...
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Connect MSSQL
|
||||
// Connect to MSSQL and select the database
|
||||
$link = mssql_connect('MANGO\SQLEXPRESS', 'sa', 'phpfi');
|
||||
mssql_select_db('php', $link);
|
||||
|
||||
|
@ -64,14 +64,11 @@ $sql = 'SELECT [name], [age] FROM [php].[dbo].[persons]';
|
|||
$query = mssql_query($sql, $link);
|
||||
|
||||
// Iterate through returned records
|
||||
do
|
||||
{
|
||||
while($row = mssql_fetch_row($query))
|
||||
{
|
||||
// Handle record ...
|
||||
}
|
||||
}
|
||||
while(mssql_next_result($query));
|
||||
do {
|
||||
while ($row = mssql_fetch_row($query)) {
|
||||
// Handle record ...
|
||||
}
|
||||
} while (mssql_next_result($query));
|
||||
|
||||
// Clean up
|
||||
mssql_free_result($query);
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Connect to MSSQL
|
||||
// Connect to MSSQL and select the database
|
||||
$link = mssql_connect('KALLESPC\SQLEXPRESS', 'sa', 'phpfi');
|
||||
mssql_select_db('php', $link);
|
||||
|
||||
|
@ -63,35 +63,31 @@ echo '<table border="1">';
|
|||
$header = false;
|
||||
|
||||
// Iterate through returned results
|
||||
while($row = mssql_fetch_array($data))
|
||||
{
|
||||
// Build the table header
|
||||
if(!$header)
|
||||
{
|
||||
echo '<thead>';
|
||||
echo '<tr>';
|
||||
while ($row = mssql_fetch_array($data)) {
|
||||
// Build the table header
|
||||
if (!$header) {
|
||||
echo '<thead>';
|
||||
echo '<tr>';
|
||||
|
||||
for($i = 1; ($i + 1) <= mssql_num_fields($data); ++$i)
|
||||
{
|
||||
echo '<td>' . ucfirst($row[$i]) . '</td>';
|
||||
}
|
||||
for ($i = 1; ($i + 1) <= mssql_num_fields($data); ++$i) {
|
||||
echo '<td>' . ucfirst($row[$i]) . '</td>';
|
||||
}
|
||||
|
||||
echo '</tr>';
|
||||
echo '</thead>';
|
||||
echo '<tbody>';
|
||||
echo '</tr>';
|
||||
echo '</thead>';
|
||||
echo '<tbody>';
|
||||
|
||||
$header = true;
|
||||
}
|
||||
$header = true;
|
||||
}
|
||||
|
||||
// Build the row
|
||||
echo '<tr>';
|
||||
// Build the row
|
||||
echo '<tr>';
|
||||
|
||||
foreach($row as $value)
|
||||
{
|
||||
echo '<td>' . $value . '</td>';
|
||||
}
|
||||
foreach($row as $value) {
|
||||
echo '<td>' . $value . '</td>';
|
||||
}
|
||||
|
||||
echo '</tr>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
// Close table
|
||||
|
|
|
@ -99,7 +99,7 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Connect to the database server
|
||||
// Connect to MSSQL and select the database
|
||||
$link1 = mssql_pconnect('MANGO\SQLEXPRESS', 'sa', 'phpfi');
|
||||
mssql_select_db('php', $link1);
|
||||
|
||||
|
|
|
@ -79,9 +79,8 @@
|
|||
// Connect to MSSQL
|
||||
$link = mssql_connect('KALLESPC\SQLEXPRESS', 'sa', 'phpfi');
|
||||
|
||||
if(!$link || !mssql_select_db('php', $link))
|
||||
{
|
||||
die('Unable to connect or select database!');
|
||||
if (!$link || !mssql_select_db('php', $link)) {
|
||||
die('Unable to connect or select database!');
|
||||
}
|
||||
|
||||
// Do a simple query, select the version of
|
||||
|
|
|
@ -83,16 +83,16 @@
|
|||
$query = mssql_query('SELECT [username] FROM [php].[dbo].[userlist]');
|
||||
|
||||
// Check if there were any records
|
||||
if(!mssql_num_rows($query))
|
||||
if (!mssql_num_rows($query))
|
||||
{
|
||||
echo 'No records found';
|
||||
echo 'No records found';
|
||||
}
|
||||
else
|
||||
{
|
||||
for($i = 0; $i < mssql_num_rows($query); ++$i)
|
||||
{
|
||||
echo mssql_result($query, $i, 'username'), PHP_EOL;
|
||||
}
|
||||
for ($i = 0; $i < mssql_num_rows($query); ++$i)
|
||||
{
|
||||
echo mssql_result($query, $i, 'username'), PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
// Free the query result
|
||||
|
@ -121,16 +121,12 @@ Ross
|
|||
$query = mssql_query('SELECT [username] FROM [php].[dbo].[userlist]');
|
||||
|
||||
// Check if there were any records
|
||||
if(!mssql_num_rows($query))
|
||||
{
|
||||
echo 'No records found';
|
||||
}
|
||||
else
|
||||
{
|
||||
while($row = mssql_fetch_array($query))
|
||||
{
|
||||
echo $row['username'], PHP_EOL;
|
||||
}
|
||||
if (!mssql_num_rows($query)) {
|
||||
echo 'No records found';
|
||||
} else {
|
||||
while ($row = mssql_fetch_array($query)) {
|
||||
echo $row['username'], PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
// Free the query result
|
||||
|
|
Loading…
Reference in a new issue