Hi,
Hierbij deel ik mijn 2e gemaakte class, een MySQL static class.
Hiermee kan je een verbinding opzetten, en alle algemene MySQL functies. Ik wil het graag in OOP, maar omdat ik een beginner ben met OOP, weet ik niet precies wat ik nog meer OOP kan schrijven in de class.
Tips zijn welkom!
Hierbij deel ik mijn 2e gemaakte class, een MySQL static class.
Hiermee kan je een verbinding opzetten, en alle algemene MySQL functies. Ik wil het graag in OOP, maar omdat ik een beginner ben met OOP, weet ik niet precies wat ik nog meer OOP kan schrijven in de class.
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/**
* @ Product: MySQL static class
* @ Author: Joey Blankendaal
* @ Website: JoeyBlankendaal.com
* @ Date: 10 May 2012
* @ Class name: MySQL
* @ Copyright: (C) 2010 - 2012 Joey Blankendaal - All rights reserved
*
* Redistributions of source code must retain the above copyright
* notice and this (list of) condition(s).
*/[/COLOR]
[URL="http://www.php.net/class"]class[/URL] MySQL
[COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #0000BB]$connect_error[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #0000BB]$select_db_error[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #0000BB]$query_error[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/private"]private[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #0000BB]$connection[/COLOR] [COLOR= #007700]=[/COLOR] null[COLOR= #007700];[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] Connect[COLOR= #007700]([/COLOR][COLOR= #0000BB]$dbServer[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$dbUsername[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$dbPassword[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$dbDatabase[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700])
{[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700](!@[/COLOR][URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$dbServer[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$dbUsername[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$dbPassword[/COLOR][COLOR= #007700]))
{[/COLOR]
[COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]connect_error [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]Kon niet verbinden met de database, de geselecteerde database bestaat niet.[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]connect_error[COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700](!@[/COLOR][URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$dbDatabase[/COLOR][COLOR= #007700]))
{[/COLOR]
[COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]select_db_error [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]Kon niet verbinden met de database, de server, username of password klopt niet.[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]select_db_error[COLOR= #007700];
}
}[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] Query[COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])
{[/COLOR]
[COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700],[/COLOR] self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$connection[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700](![/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]())
{[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$query[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
[COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]query_error [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]Kon de query niet uitvoeren, dit is de error:[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]();[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]query_error[COLOR= #007700];
}
}[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] NumRows[COLOR= #007700]([/COLOR][COLOR= #0000BB]$resource[/COLOR][COLOR= #007700])
{[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$resource[/COLOR][COLOR= #007700]);
}[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] Fetch[COLOR= #007700]([/COLOR][COLOR= #0000BB]$resource[/COLOR][COLOR= #007700])
{[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$resource[/COLOR][COLOR= #007700]);
}[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] FetchObject[COLOR= #007700]([/COLOR][COLOR= #0000BB]$resource[/COLOR][COLOR= #007700])
{[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/mysql_fetch_object"]mysql_fetch_object[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$resource[/COLOR][COLOR= #007700]);
}[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] FetchArray[COLOR= #007700]([/COLOR][COLOR= #0000BB]$resource[/COLOR][COLOR= #007700])
{[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$resource[/COLOR][COLOR= #007700]);
}[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] Escape[COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700])
{[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$string[/COLOR][COLOR= #007700]);
}[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] Info[COLOR= #007700]()
{[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/mysql_info"]mysql_info[/URL][COLOR= #007700]([/COLOR]self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$connection[/COLOR][COLOR= #007700]);
}[/COLOR]
[URL="http://www.php.net/public"]public[/URL] [URL="http://www.php.net/static"]static[/URL] [COLOR= #007700]function[/COLOR] Close[COLOR= #007700]()
{[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [URL="http://www.php.net/mysql_close"]mysql_close[/URL][COLOR= #007700]([/COLOR]self[COLOR= #007700]:[/COLOR][COLOR= #007700]:[/COLOR][COLOR= #0000BB]$connection[/COLOR][COLOR= #007700]);
}
}[/COLOR]
?> Tips zijn welkom!

