通过PHP安全连接到MySQL数据库

时间:2016-05-03 02:44:25

标签: php html mysql sql database

是否有更安全或标准的方式通过php访问您的mysql数据库然后明确写下您的凭据,如下所示......

$servername = "localhost";
$username = "user1";
$password = "pass1";
$dbname = "test-db";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

如果是这样,任何想法可以在哪里找到更多信息并研究这个主题?

1 个答案:

答案 0 :(得分:2)

如果您在public ObservableCollection<MemoryItem> MemoryItems { get; set; } = new ObservableCollection<MemoryItem>(); public MainPageViewModel() { } public string MemoryValue { get { return _memoryValue; } set { _memoryValue = value; OnPropertyChanged("MemoryValue"); } } public static async Task Serializer() { var folder = ApplicationData.Current.RoamingFolder; var file = await folder.CreateFileAsync("collection.json", CreationCollisionOption.ReplaceExisting); using (var stream = await file.OpenStreamForWriteAsync()) using (var writer = new StreamWriter(stream, Encoding.UTF8)) { string json = JsonConvert.SerializeObject(MemoryItems); await writer.WriteAsync(json); } } public static async Task Deserializer() { try { var folder = ApplicationData.Current.RoamingFolder; var file = await folder.GetFileAsync("collection.json"); using (var stream = await file.OpenStreamForReadAsync()) using (var reader = new StreamReader(stream, Encoding.UTF8)) { string json = await reader.ReadToEndAsync(); MemoryItems = JsonConvert.DeserializeObject<ObservableCollection<MemoryItem>>(json); } } catch (Exception) { // Handle Exception. } } 堆栈上,请将其移至环境文件中,最好是public async void OnSuspending(object sender, SuspendingEventArgs args) { SuspendingDeferral deferral = args.SuspendingOperation.GetDeferral(); await MainPageViewModel.Serializer(); deferral.Complete(); } public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args) { NavigationService.Navigate(typeof(Views.MainPage)); await MainPageViewModel.Deserializer(); await Task.CompletedTask; } 环境文件。

apache

然后你就可以在PHP中访问它了。

LAMP