Źródło:
Komentarze (0)
| | źródło pochodzi od: sympozjon Opis: Funkcja realizuje połączenie z mysql - @mysql_connect, @mysql_select_db oraz zapytanie - @mysql_query. Język: php |
<?PHP
/*
Function to simpl
ify
doing Datab
ase Queries
All that is needed is the query to execute.
Returns true
if execution w
as completed successfully.
Otherwise outputs error messages and
returns
0.
Requires
4 global variables:
$db_host The hostname / IP-Adresse
$db_user The username
$db_pass The p
assword
$db_name The datab
ase name
Version:
2.
0.
1
Date:
2000-
07-
01
Author: Jocke Selin (jocke@selincite.com)
----------------------------------------------
For direct output in the same
function
Version:
2.
0.x
Date:
2001-
03-
20
Update: rolandz (rolandhz@hotmail.com)
*/
function jquery(
$query)
{
$db_host=
'10.130.148.15';
$db_user=
'root';
$db_pass='';
$db_name=
'Focus';
// Connect to DB
if (!
$link = @
mysql_connect(
$db_host,
$db_user,
$db_pass))
{
$result =
0;
print(
"<FONT COLOR='Red'><BR><BR><HR><CENTER><B>Error connecting to $db_host!<HR></B><BR>n");
}
else
{
// Select DB
if (!@
mysql_select_db(
$db_name,
$link))
{
$result =
0;
print(
"<FONT COLOR='Red'><BR><BR><HR><CENTER><B>Error selecting $db_name!<HR></B><BR>n");
}
else
{
// Execute query
if (!
$result = @
mysql_query(
$query,
$link))
{
$result =
0;
print(
"<FONT COLOR='Red'><BR><BR><HR><CENTER><B>Error executing query!<HR></B><BR>n");
}
else
{
$fields =
mysql_num_fields(
$result);
while (
$array =
mysql_fetch_array(
$result))
{
for (
$i=
0;
$i <=
$fields;
$i++)
{
echo $array[
$i];
if (
$i <
$fields )
echo "; ";
}
echo "<BR>n";
}
}
}
}
return $result;
}
function bgn_html(
$title,
$author,
$header)
{
print (
"<HTML>n");
print (
" <HEAD>n");
printf (
" <TITLE>%s</TITLE>n",
$title);
print (
" <META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=windows-1252'>n");
printf (
" <META NAME='AUTHOR' CONTENT='%s'>n",
$author);
print (
" </HEAD>n");
print (
" <BODY BGCOLOR='#F1F1F1' TEXT='#364180'>n");
print (
" <BASEFONT FACE='Courier New'>n");
printf (
" <H1><CENTER>%s</CENTER></H1>n",
$header);
printf (
" <HR>n");
}
function end_html ()
{
print (
" </BODY>n");
print (
"</HTML>n");
}
bgn_html (
'Test PHP-Site', 'rolandz', 'Output');
jquery(
'SELECT * FROM table WHERE field = x');
end_html ();
?>
</body>
</html>
powrótTagi do źródła:
Funkcja łącząca z bazą danych, mysql, sql, bazy danych , php
Nikt jeszcze nie skomentował tego źródła.