snlildude87
Dec 26 2005, 11:45 PM
| | Recently, I recoded a part of my site so that it uses a MySQL database to store information instead of on a text file. Because my site receives a lot of traffic and it's on a shared hosting environment, the DB could potentially go down. Since I don't want to lose my visitors, I want to know if there is a way to tell when the MySQL DB is down. I know that I could add a die function along with the mysql_connect function:
CODE mysql_connect("localhost", "username", "passwordl") or die("Something here.");
I want it to do more than just print a line stating the problem--I want it to store a variable. Is there a way to do such thing?
Thanks! |
Reply
HmmZ
Dec 27 2005, 12:34 AM
id say this: db.phpCODE $sql_conn = mysql_connect("host","user","pass"); if(!$sql_conn){ $db_status = 0;} else {$db_status = 1;} Checks if a mysql connection was established, stored as a "0" or "1" Next step would be further developing that variable in the page where you want to show the status: Any other pageCODE include("db.php");
#if db is online if($db_status=="1"){ $db_status = "<img src='images/online.gif' border='0'>";} #else db is down else { $db_status = "<img src='images/offline.gif' border='0'>";}
print "Database Status: $db_status"; configure it to your own liking, once db.php is included you can make the $db_status variable anything you want  Enjoy!
Reply
snlildude87
Dec 27 2005, 12:53 AM
Hmm, I'll try that, and I'll post the status. Thanks for the help!
Reply
snlildude87
Dec 27 2005, 02:48 AM
Another question -> another post I have another question. Is there a way for MySQL and PHP to continue executing if the MySQL DB goes down?
Reply
HmmZ
Dec 27 2005, 05:47 AM
when you perform mysql querys and other things that call for the database, you seem to be always using die()? not needed, just store the query or whatever it is your using in a variable and check the query with an if...else statement. Instead of using: mysql_query("SELECT * FROM table") or die(mysql_error());you should do: $qry = mysql_query("SELECT * FROM table"); if(!$qry){$db_status = 0;} else {$db_status = 1;}Continued from where i left off  Hope this helps.
Reply
snlildude87
Dec 27 2005, 05:57 PM
Right, but say the database is down...will the rest of my script still execute or will it stop right there?
Reply
Unregistered 015
Dec 27 2005, 06:36 PM
If you used this: $qry = mysql_query("SELECT * FROM table"); if(!$qry){$db_status = 0;} else {$db_status = 1;}[/CODE] then the part in else {} will execute and everything below that. Unless, you put some exit code in that else statement, of course.
Reply
snlildude87
Dec 27 2005, 09:33 PM
QUOTE(ciroxyz @ Dec 27 2005, 03:36 PM) If you used this: $qry = mysql_query("SELECT * FROM table"); if(!$qry){$db_status = 0;} else {$db_status = 1;}[/CODE] then the part in else {} will execute and everything below that. Unless, you put some exit code in that else statement, of course. Gotcha. So the rest will continue to execute. Thanks!
Reply
Recent Queries:--
travian detect pushing? - 211.11 hr back. (1)
-
"detecting imei remotely" - 879.76 hr back. (3)
Similar Topics
Keywords : php, code, detect, mysql, db, create, var, db
- Create Table - Mysql Code - Help
(1)
Mysql Error
(3) ok i need some more help from the wonderful coders here at Trap. I'm almost done with my CMS
script, but i'm having a problem with the installer.php file, when it trys to inseret the user
data into the database i keep getting the following error: CODE mySQL Error: You have an
error in your SQL syntax; check the manual that corresponds to your MySQL server version for the
right syntax to use near ';INSERT INTO `members` (`id`, `name`,
`username`, `password`, `email`, `title`) ' at lin....
Php Source Code Unveiled In Browser?
is that possible? (7) I am quite new to PHP and this concern came to my mind after playing around a bit with it... When
PHP is not correctly configured on the web server the source code of a php file we try to access
through a browser will be shown instead of the result of the code itself. This will normally not
happen when PHP is working properly, but I was just wondering if it could still be possible to see
that code if a user wanted to or if something on the server failed. This would for example expose
sensitive information like mysql passwords and so on... Is anything like that possib....
Html Form!
Using MySQL?! (4) Hey, I need your help again! I need some good working tutorial how I can update my SQL through
HTML form. I did use some tutorials online found with the help of google; but they do not work
properly; I mean there are still small mistakes. I need to have a good tutorial to follow. It
should be based on security and more things. It has to be done in proper way.......
Malicious Code Injection
(3) Hi everyone! This is my first post, so be kind! Basically, I'm trying to get a free
host together so am writing some posts. Here's a little summin' summin' about malicious
code injection with PHP applications. Basically, this security exploit is one of the oldest tricks
in the books and all comes down to the fact that PHP allows execution of both local and remote
scripts with the SAME function... dur. Anyway, this is how it works. Image you've just employed
a young go getter, straight outta uni, who has found becoming a Jack of all trades a ....
Best Php And Mysql Editor For Noobs
anyone any php or mysql editor that is good for noob (6) hi there guys, from my previous posting, i am a noob in php and mysql programming. I want to know
if there are any php and mysql editors which are best for me as a noob. i appreciate your kindness
....
Php And Mysql Programming
anyone knows a code for mysql and php (2) hi everyone! I am making a program using php and mysql...I am a noob on this so i need your
help guys...I want to make a simple program that will some values and then store them on a database
and then retrieve them...uhmm let me give an example out put of what i need. This is the example
say..: Enter First Name: Enter Last Name:
Enter Age: Enter Address: ..those
are the data needed for input values...my question now is how can I make a database....
Best Sites For Learning Php-mysql
(4) Hi I was reminded of this earlier by a post in a topic, meant to post it but forgot and the topic on
php books reminded me. Well anyway there is tyhschools for learning php (unless someone else knows
a better 1) but I wan't to know what is the best site for using php with mysql (using
phpmyadmin) also whats the difference between postgresql and mysql? though I must admit the
postgresql version of phpmyadmin whatever it's called looks better (visually)!....
Tools Needed!
PHP & MySQL (9) Hello, everyone! I need some tools for those two things to test PHP scripts coming together with
database on my laptop, instead checking them on a web-server which takes time.....
Php Code Needed Iii
(10) Hello, everyone. I need your help again! Who might create the PHP code, the picture is
above this text. Basically, I want when the user fill in all the information in this form, it
automatically was sent to my email. And, then, the dialog box appears or on the same window, it was
said that your request has been sent. Moreover, if the user did not fill the entire information,
the dialog box appears stating that you did not fill some field. Thanks, for help. You always do
that.....
Php Code?
Mathematical Applications (12) Hello, everyone. The help is needed again. How can I make calculator in PHP language? That will act
like that a user just type in the fields known values, then click the button, and it's going to
be solved automatically. In other words, have can I write a formula in PHP, how to plug it inside
that language. For example, the formula to find a peremeter of square is: P=4a. So, a user
just can write the known value which is peremeter itself and it will find the side of a square; and
vice versa. If you can write many things how to do such formulas, such as comp....
Php Code Needed
Working Together? (5) Hello, everyone. I need your help again. This forum is quite good for it. Well, I need create a
registration form for my web-site using PHP and SQL. The information it should contain: 1) User
Name 2) First Name 3) Last Name 4) Password 5) e-mail Address 6) Security Image: that images helps
to protect a random registration, for instance, 56+2=where user have to type an answer in order to
finish registration. That's all for today. Anymore things, I will post another post over here.
....
Php Code
Needed?! (15) Well, I am a novice in PHP programming, so there is a script which I wanna get: 1. You go the
web-site 2. On the main screen, there is a some kind of field windows, the one you get used to type
in, when you go to google, for instance. 3. He or she types her email address and it's going to
be saved in my SQL database. 4. That's it. Help me if you can.....
Use Rss In Php Code
(3) so, how can I make RSS reader on my website? thanks in advance....
Php + Mysql Question!
While inserting data into MySQL, how can I know if the data I'm in (4) Basically, I want to know if the Data I'm inserting through a Form is already there or not. Sort
of a Username registration page. I have this, but it doesn't appear to work... CODE
$result = mysql_query("SELECT * FROM users WHERE
username='$username'"); if($result == 1) { echo
'<h1>ERROR!</h1>The username you have chosen already exists!'; }
....
Will This Code Work
php linking script ?p= (5) hi i'm not that great at php so i'm not to sure if this will work or not. but what i want to
do is be able to use ?p=staff or what ever page name, with out the php extion, and i would like to
no if this simple script i made would work. the code is: CODE <?php $p =
$_GET['p']; if ( !empty($p) &&
file_exists('./' . $p . '.php') && stristr( $p, '.'
) == False ) { // pages = directory where you store your pages $file = './'
. $p . '....
Mysql Won't Update
(4) Ok, so I'm making some arcade administration software so I don't have to add games the hard
way, well anyway, one of the features I have is that on the homepage is a featured author and as
such I just have it so it updates one line in the mySQL. Well, the page with the form passes on the
varibles fine and the updating page recieves them because I echoed everything, then I build the
query and I even echo the query and it comes out exactly how I want it to, but for some reason, the
database itself won't update even though all the varibles are there. Here's....
[php/mysql]id Trouble [resolved]
(3) session_start(); include "database.php"; if (!$_SESSION || $_SESSION { // User
not logged in, redirect to login page Header("Location: main.php"); } $result =
mysql_query("select * from users order by id asc"); while($r=mysql_fetch_array($result))
{ $username=$r ; $info=$r ; $msn=$r ; $email=$r ;
$id=$r ; $password=$r ; $userlevel=$r ; echo "
user ID User Level U....
[mysql/php]need Som Basic Help
(13) QUOTE session_start(); include "database.php"; include "edit.inc.php"; if (!$_SESSION
) { // User not logged in, redirect to login page Header("Location: main.php"); }
if(isset($_POST )){ $email = $_POST ; $msn = $_POST ; $info =
$_POST ; $updateemail = "UPDATE users SET email = '$email', msn =
'$msn', info = '$info' WHERE username = '$username'";
mysql_query($updateemail) or die("culd not edit your info"); echo "info updated"; } //
Display log....
Html Code Tester. Online Script
(15) Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
Current script: CODE <?php //Save this as something like htmltest.php function
CheckForm() { $html_unsafe=$_POST['code']; //Gives us our user
input $html_safe=str_replace("<?php"," ",$html_unsafe);
//Starts security measures $html_safe=str_replace("?>","
",$html_sa....
Wap Source Code Viewer
Mobile/wap source code viewer page (4) This is a source code viewer that will workl on wap/mobile sites but you can easily convert it to
work on web im sure ;-) CODE <? header("Content-Type:
text/vnd.wap.wml"); echo '<?xml version="1.0"
encoding="utf-8"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <head><meta
http-equiv="Cache-Control" content="no-cache"
forua="true"/></head> <card title="s60.nerds.....
Creating Profiles In Php/mysql ?
(7) i've started to learn php..im familiar to basics of php and mysql now.Now for example i want
that some user can register to my website , and after that he can Login and log out , and he can see
his profile.is there any tutorial about this ? or any helping url .. or any helping answer please
/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />....
Dynamic Image / Signature Generator
a simple code to change text on an image (12) In search of dynamically changing quote, saying or all other types of text on an image I came across
a code that I have modified to fit my initial usage. This procedure requires two files and short
knowledge of PHP. If you are familiar with Trap17's sig rotation code you will understand this
procedure very fast. Code 1: dynamic_sig.php (you can rename this to index.php and you'll see
at the end why) Code 2: a simple text file named anything (I will call it name.txt ) Code 1
CODE <?php header("Content-type: image/png"); ....
Adapting Html Code Embed To Work On Phpnuke
Help With This Html Code Pls (7) QUOTE how can get this html code to work on my phpnuke site? what tags would i
have to enable in the $Allowable HTML part of my config.php file?? Edited topic title. Moved
to Programming. ....
Subquery In Mysql
(5) Is there anyway to make subqueries work in MySQL? I'm pretty certain someone out there knows
how. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Can anyone help?
CODE Select * from ITEMS where ID="Select Max(ID) from ORDERS"; This works
for MSAccess and SQL Server but why not in MySQL? I'll be writing some reports and I've
shifted database from MSAccess to MySQL. Help! Thanks.....
Can You Add Images Into A Mysql Database?
Using Php? (20) I'm learning php in class right now, but I'm still not that good at it, what I'm
wondering is when I write the php so that it can connect with a database, can I at the same time
have it that it is able to display back images that I choose. Like, I want a search feature, where
you can search for a keyword, and it will bring back a list of all the possible entries with that
keyword, but each of these entries will have a photo associated with it. Now, do I put these image
files directly into the database, or do I write the code to link them from my files to th....
Increment A Mysql Column
how to increment a MySQL column one unit (7) Hi, I have a column in a MySQL table which contains a counter of the views of the object described
by this table. I would like to increment this value by one everytime the object is viewed. Obviously
came into my mind the possibility of retrieving the value of this field, store it in a variable
increment this value by one and perform an UPDATE query again with this new value. My question is if
there is a MySQL option to update the field with its actual value plus an unit increment. I hope you
understand the issue.....
Change Permission With Php Code
code to change files' and folders' permissions? (3) As everyone know, there two ways (that I can think of) to change files' and directories'
permissions. One is to change it in your cPanel's Disk Manager and the other is with an FTP
client that supports chmod. Well, I'm doing something for my site that requires files to have
full permissions (Execute, Write, and Read on all three groups). At first, I thought that if I made
the directory 777, then every file created in that directory will be 777 as well. I'm wrong. An
alternative to doing this is to change each file permission myself, but that would be....
Php Clock
source Code (7) Hi Every one i find this code its very easy simple php clock i think you can use it /blink.gif'
border='0' style='vertical-align:middle' alt='blink.gif' /> CODE <? // Binary Clock //
script copyrightŠ 2002 Andreas Tscharnuter // questions? contact: psychodad@psychodad.at ||
[url=http://www.psychodad.at/clock/]http://www.psychodad.at/clock/[/url] //
free to use, copy and modify but leave comments untouched;) // just include this file where
your binary clock should appear // version 1.2 03 September 2003 // below you can ....
How do you test your php code
(80) We know that php is a server side scripting language. So we will need a server with the php parser
to parse/test our code. How are you doing that. Do you upload it to a server for testing or did you
instal php and the server (apache) on your computer (localhost)....
Looking for php, code, detect, mysql, db, create, var, db
|
*RANDOM STUFF*
*SIMILAR VIDEOS*
Searching Video's for php, code, detect, mysql, db, create, var, db
*MORE FROM TRAP17.COM*
|
advertisement
|
|