?
Solved

mssql database control with php

Posted on 2011-05-13
4
Medium Priority
?
289 Views
Last Modified: 2012-05-11
I'm making a PHP script for controlling my mssql databases. But I ran into a couple of problems.

The first problem is that I want to make a combobox out of all the databases in my microsoft SQL server. With following code, but it doesn't seem to work.
 
SELECT name from sys.databases where owner_sid != 0x01

Open in new window



My next problem is, that I have to run follwing SQL command:
 
RESTORE FILELISTONLY FROM DISK = 'C:\Databases\Breda\backup\Backup.BAK'

Open in new window

But I need to get the first column of every row, and place that in 2 variables, but I don't know how to do that.

Can anyone provide me this code?
0
Comment
Question by:Silencer001
  • 3
4 Comments
 
LVL 1

Expert Comment

by:beeblebrox42
ID: 35753446
To answer your first problem, I believe you have to do this:

"SELECT name from master.sysdatabases where owner_sid != 0x01 "

I am not understanding your second question completly
0
 

Author Comment

by:Silencer001
ID: 35753593
And how do I put that code in a Combobox?

My second question is that if I execute that SQL statement, the following result comes up
 Output sql commandAnd I need to put the 2 LogicalNames into a variable.

So that row 1 column 1 (Breda) = $name1
and row 2 column 3 (Breda_log) = $name2

Because I need to use those 2 variables in the following code.
0
 

Accepted Solution

by:
Silencer001 earned 0 total points
ID: 35775234
Found the solution, for the first problem it was:
 
$query = mssql_query("SELECT name FROM sys.databases");

		// Check if there were any records
				if (!mssql_num_rows($query)) {
					echo 'No records found';
					} else {
					echo "<select name='dbname'>";
						for ($i = 0; $i < mssql_num_rows($query); ++$i) {
						$lookup = mssql_result($query, $i, 'name');
							if ($lookup != "master" && $lookup != "tempdb" && $lookup != "model" && $lookup != "msdb" && $lookup != "SBO-COMMON" && $lookup != "RSP")
								{
								echo "<option value='".$lookup."'>".$lookup."</option>";
								}
						}
					echo "</select>";
					}
				mssql_free_result($query);
				?>

Open in new window


and for the second problem it was:
 
$query = mssql_query("restore filelistonly from disk = '".$locatie."'");
	$lognaam1 = mssql_result($query, '0', 'LogicalName');
	$lognaam2 = mssql_result($query, '1', 'LogicalName');

Open in new window

0
 

Author Closing Comment

by:Silencer001
ID: 35807144
Code works for 100%
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question