# SQL db check

**URL:** <https://community.unix.com/t/sql-db-check/318079>\
**Category:** Web Development\
**Created:** [October 11, 2012, 10:58am UTC](https://community.unix.com/t/sql-db-check/318079 "2012-10-11T10:58:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![graphicsman](https://community.unix.com/letter_avatar/graphicsman/32/6_449c533f586939b6e5f246632a46421f.png) [@graphicsman](https://community.unix.com/u/graphicsman)\
**Post date:** [October 11, 2012, 10:58am UTC](https://community.unix.com/t/sql-db-check/318079/1 "2012-10-11T10:58:41Z")

</div>

Ive debated this for awhile after I ran into a crap load of issues with my hosting's SQL server. I was curious to know if there is a way to write a db check into my .htaccess file that would verify if a connection is present and if not transfer to another domain?? I know it can be done manually in Cpanel (domain fowarding) but I would like a way for this to be into play instead of SQL errors. Ideas??

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [October 11, 2012, 11:16am UTC](https://community.unix.com/t/sql-db-check/318079/2 "2012-10-11T11:16:22Z")

</div>

Which SQL?

But probably no. That's the sort of thing you'd do in PHP. If you can check before PHP actually outputs anything, you can dump a header() to redirect then quit if the SQL doesn't work.

---

<div class="post-metadata">

**Author:** ![graphicsman](https://community.unix.com/letter_avatar/graphicsman/32/6_449c533f586939b6e5f246632a46421f.png) [@graphicsman](https://community.unix.com/u/graphicsman)\
**Post date:** [October 11, 2012, 11:26am UTC](https://community.unix.com/t/sql-db-check/318079/3 "2012-10-11T11:26:38Z")

</div>

> [@corona688](#):
>
> Which SQL?
> 
> But probably no. That's the sort of thing you'd do in PHP. If you can check before PHP actually outputs anything, you can dump a header() to redirect then quit if the SQL doesn't work.

I actually found something like that written in PHP but i didnt like how it required you to enter the db name, password, and user. I thought that would be a major security risk.

It was [here](http://www.ardamis.com/2008/05/26/a-php-script-for-testing-a-mysql-database-connection/)

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [October 11, 2012, 12:55pm UTC](https://community.unix.com/t/sql-db-check/318079/4 "2012-10-11T12:55:36Z")

</div>

Yes, that one would be.

Hardcode your own simple one with fixed connection details and it won't be vulnerable to injection.
